﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;

namespace SchoolAdministration
{
    public partial class StaffAttence : System.Web.UI.Page
    {
        private readonly BlStaff _blstaff = new BlStaff();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadStaff();
            }
        }
        public void LoadStaff()
        {
            List<Staff> lstaff = new List<Staff>();
            lstaff = _blstaff.GetAllStaff();
            GridViewStaffList.DataSource = lstaff;
            GridViewStaffList.DataBind();
        }
        

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridViewStaffList.Rows)
            {
                StaffAttendence attendence = new StaffAttendence();

                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox Present = (CheckBox)row.Cells[0].FindControl("ChkPresent");
                    CheckBox Absent = (CheckBox)row.Cells[0].FindControl("ChkAbsent");
                    CheckBox Late = (CheckBox)row.Cells[0].FindControl("ChkLate");
                    attendence.Present = Present.Checked;
                    attendence.Absent = Absent.Checked;
                    attendence.Late = Late.Checked;
                    attendence.AttendDate = DateTime.Now;
                    attendence.StaffId = Int32.Parse(row.Cells[0].Text);

                    int result = _blstaff.SaveAttendence(attendence);
                    if (result > 0)
                    {
                        Response.Write("Attended");
                    }
                    // DataTable dt = DataManager.DeleteNotification(notifyid);
                    //loadgrid();

                }
            }

        }
    }
}